package com.tan.service.impl;

import com.tan.pojo.Menu;
import com.tan.mapper.MenuMapper;
import com.tan.service.IMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tan.utils.BuildMenuTreeUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 菜单表 服务实现类
 * </p>
 *
 * @author tanRuYi
 * @since 2021-08-25
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {

    @Override
    public List<Menu> buildMenuTree(String username) {

        final List<Menu> menuList = this.baseMapper.getMenuListByUsername(username);

        return BuildMenuTreeUtil.buildMenuTree(menuList);
    }

    @Override
    public List<Menu> getMenuListByRoleId(Long id) {
        return this.baseMapper.getMenuListByRoleId(id);
    }

    @Override
    public Menu getMenuByMenuId(Long menuId) {
        return this.baseMapper.selectById(menuId);
    }
}
